<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\adminapi\lists\skits;


use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\skits\Skits;
use app\common\model\skits\SkitsEpisodes;
use app\common\lists\ListsSearchInterface;
use app\common\service\video\OssVideoService;
use app\common\service\wechat\WechatService;


/**
 * SkitsEpisodes列表
 * Class SkitsEpisodesLists
 * @package app\adminapi\lists
 */
class SkitsEpisodesLists extends BaseAdminDataLists implements ListsSearchInterface
{


    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public function setSearch(): array
    {
        return [
            '%like%' => ['episodes_name'],
            '='      => ['id', 'skits_id', 'episodes_order'],
        ];
    }


    /**
     * @notes 获取列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public function lists(): array
    {
        $isDyUpload = $this->params['is_dy_upload'] ?? 0;
        $query      = SkitsEpisodes::where($this->searchWhere);
        if ($isDyUpload) {
            $query->whereIn('dy_status', [1, 2]);
        }
        $list = $query->field('id,skits_id,episodes_order,episodes_name,episodes_path,wechat_media_id,douyin_media_id,wechat_order,dy_status,status,create_time, update_time')
            ->limit($this->limitOffset, $this->limitLength)
            ->order('episodes_order')
            ->select();

        foreach ($list as &$item) {
            $item->video_url = $item->episodes_path ?
                OssVideoService::getVideoUrl(
                    $item['skits_id'], $item['episodes_order'], $item['episodes_path']
                ) : '';
        }

        return $list->toArray();
    }


    /**
     * @notes 获取数量
     * @return int
     * @author likeadmin
     * @date 2024/07/13 15:05
     */
    public function count(): int
    {
        return SkitsEpisodes::where($this->searchWhere)->count();
    }

}
